﻿<internals:PageBase
    x:Class="JV.Com.Views.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:dvm="using:JV.Com.DesignViewModels"
    xmlns:i="using:Microsoft.Xaml.Interactivity"
    xmlns:core="using:Microsoft.Xaml.Interactions.Core"
    xmlns:wrappers="using:JV.Com.Views.Wrapper"
    mc:Ignorable="d" 
    xmlns:prism="using:Microsoft.Practices.Prism.StoreApps"
    xmlns:internals="using:JV.Com.Internals"
    prism:ViewModelLocator.AutoWireViewModel="true"
    d:DataContext="{d:DesignInstance dvm:MainPageDesignViewModel, IsDesignTimeCreatable=True}">
    
    <Hub HorizontalContentAlignment="Stretch">
        <i:Interaction.Behaviors>
            <core:EventTriggerBehavior EventName="SectionHeaderClick">
                <core:InvokeCommandAction Command="{Binding OnSectionHeaderClickCommand}" />
            </core:EventTriggerBehavior>
        </i:Interaction.Behaviors>
        <Hub.Transitions>
            <TransitionCollection>
                <EntranceThemeTransition />
            </TransitionCollection>
        </Hub.Transitions>
        <Hub.Header>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="80"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Button  x:Name="backButton" Style="{StaticResource NavigationBackButtonNormalStyle}"
                    Margin="-1,-1,39,0" 
                    VerticalAlignment="Top"
                    Command="{Binding GoBackCommand}"
                    AutomationProperties.Name="Back"
                    AutomationProperties.AutomationId="BackButton"
                    AutomationProperties.ItemType="Navigation Button"/>
                <TextBlock x:Name="pageTitle" Text="{Binding PageTitle}" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1" 
                    VerticalAlignment="Top" IsHitTestVisible="false" TextWrapping="NoWrap" />
                <SearchBox
                    Grid.Column="2" VerticalAlignment="Center"
                    Height="35" Width="270"
                    PlaceholderText="Rechercher" QueryText="{Binding Query}"
                    SuggestionsRequested="SearchBox_SuggestionsRequested"
                    QuerySubmitted="SearchBox_QuerySubmitted" />
            </Grid>
        </Hub.Header>
        <HubSection IsHeaderInteractive="True" Header="Actualités" x:Name="NewsSection">
            <HubSection.ContentTemplate>
                <DataTemplate>
                    <GridView ItemsSource="{Binding LastNews}" SelectionMode="None" IsItemClickEnabled="True"
                              ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                              ScrollViewer.VerticalScrollBarVisibility="Disabled" Width="900" ScrollViewer.HorizontalScrollMode="Disabled">
                        <i:Interaction.Behaviors>
                            <core:EventTriggerBehavior EventName="ItemClick">
                                <core:InvokeCommandAction Command="{Binding OpenNewsCommand}" />
                            </core:EventTriggerBehavior>
                        </i:Interaction.Behaviors>
                        <GridView.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="140" />
                                        <RowDefinition Height="Auto" MaxHeight="40" />
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>
                                    <Image Source="{Binding ImageUrl}" Stretch="UniformToFill" Margin="0, 0, 0, 10"
                                           VerticalAlignment="Center" HorizontalAlignment="Center" />
                                    <ItemsControl ItemsSource="{Binding Machines}" VerticalAlignment="Bottom" HorizontalAlignment="Right">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <Image Stretch="None" Source="{Binding Converter={StaticResource BytesToImageConverter}}" />
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <StackPanel Orientation="Horizontal" />
                                            </ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                        <ItemsControl.ItemContainerStyle>
                                            <Style TargetType="ContentPresenter">
                                                <Setter Property="Margin" Value="0, 0, 5, 0" />
                                            </Style>
                                        </ItemsControl.ItemContainerStyle>
                                    </ItemsControl>
                                    <TextBlock Text="{Binding Title}" Style="{StaticResource TitleItemTextBlockStyle}"
                                               Grid.Row="1" TextWrapping="Wrap" TextTrimming="WordEllipsis" />
                                    <TextBlock Text="{Binding Summary}" Grid.Row="2" Style="{StaticResource SummaryItemTextBlockStyle}"
                                                   TextWrapping="Wrap" TextTrimming="WordEllipsis" />
                                </Grid>
                            </DataTemplate>
                        </GridView.ItemTemplate>
                        <GridView.ItemContainerStyle>
                            <Style TargetType="GridViewItem" BasedOn="{StaticResource CustomGridViewItemStyle}">
                                <Setter Property="Padding" Value="5" />
                                <Setter Property="VerticalContentAlignment" Value="Top" />
                            </Style>
                        </GridView.ItemContainerStyle>
                        <GridView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <ItemsWrapGrid ItemHeight="250" ItemWidth="300" />
                            </ItemsPanelTemplate>
                        </GridView.ItemsPanel>
                    </GridView>
                </DataTemplate>
            </HubSection.ContentTemplate>
        </HubSection>
        <HubSection Header="Tests" IsHeaderInteractive="True">
            <DataTemplate>
                <GridView ItemsSource="{Binding LastTests}" SelectionMode="None" Width="300"
                          ScrollViewer.HorizontalScrollBarVisibility="Disabled" IsItemClickEnabled="True">
                    <i:Interaction.Behaviors>
                        <core:EventTriggerBehavior EventName="ItemClick">
                            <core:InvokeCommandAction Command="{Binding OnArticleClickCommand}" />
                        </core:EventTriggerBehavior>
                    </i:Interaction.Behaviors>
                    <GridView.ItemTemplate>
                        <DataTemplate>
                            <wrappers:GameArticleWrapper DataContext="{Binding}" />
                        </DataTemplate>
                    </GridView.ItemTemplate>
                    <GridView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <ItemsWrapGrid ItemHeight="80" ItemWidth="300" />
                        </ItemsPanelTemplate>
                    </GridView.ItemsPanel>
                    <GridView.ItemContainerStyle>
                        <Style TargetType="GridViewItem" BasedOn="{StaticResource CustomGridViewItemStyle}">
                            <Setter Property="Padding" Value="2" />
                            <Setter Property="VerticalContentAlignment" Value="Top" />
                            <Setter Property="HorizontalContentAlignment" Value="Left" />
                        </Style>
                    </GridView.ItemContainerStyle>
                </GridView>
            </DataTemplate>
        </HubSection>
        <HubSection Header="Aperçus" IsHeaderInteractive="True">
            <DataTemplate>
                <GridView ItemsSource="{Binding LastPreviews}" SelectionMode="None" Width="300"
                          ScrollViewer.HorizontalScrollBarVisibility="Disabled" IsItemClickEnabled="True">
                    <i:Interaction.Behaviors>
                        <core:EventTriggerBehavior EventName="ItemClick">
                            <core:InvokeCommandAction Command="{Binding OnArticleClickCommand}" />
                        </core:EventTriggerBehavior>
                    </i:Interaction.Behaviors>
                    <GridView.ItemTemplate>
                        <DataTemplate>
                            <wrappers:GameArticleWrapper DataContext="{Binding}" />
                        </DataTemplate>
                    </GridView.ItemTemplate>
                    <GridView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <ItemsWrapGrid ItemHeight="80" ItemWidth="300" />
                        </ItemsPanelTemplate>
                    </GridView.ItemsPanel>
                    <GridView.ItemContainerStyle>
                        <Style TargetType="GridViewItem" BasedOn="{StaticResource CustomGridViewItemStyle}">
                            <Setter Property="Padding" Value="2" />
                            <Setter Property="VerticalContentAlignment" Value="Top" />
                            <Setter Property="HorizontalContentAlignment" Value="Left" />
                        </Style>
                    </GridView.ItemContainerStyle>
                </GridView>
            </DataTemplate>
        </HubSection>
        <HubSection IsHeaderInteractive="True" Header="Dossiers">
            <HubSection.ContentTemplate>
                <DataTemplate>
                    <GridView ItemsSource="{Binding LastFolders}" SelectionMode="None" IsItemClickEnabled="True"
                              ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled"
                              Width="300" ScrollViewer.HorizontalScrollMode="Disabled">
                        <i:Interaction.Behaviors>
                            <core:EventTriggerBehavior EventName="ItemClick">
                                <core:InvokeCommandAction Command="{Binding OnArticleClickCommand}" />
                            </core:EventTriggerBehavior>
                        </i:Interaction.Behaviors>
                        <GridView.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="100" />
                                        <RowDefinition Height="Auto" MaxHeight="40" />
                                        <RowDefinition Height="20" />
                                    </Grid.RowDefinitions>
                                    <Image Source="{Binding SmallImageUrl}" Stretch="Fill" Margin="0, 0, 0, 10" />
                                    <ItemsControl ItemsSource="{Binding Machines}" VerticalAlignment="Bottom" HorizontalAlignment="Right">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <Image Stretch="None" Source="{Binding Converter={StaticResource BytesToImageConverter}}" />
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <StackPanel Orientation="Horizontal" />
                                            </ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                        <ItemsControl.ItemContainerStyle>
                                            <Style TargetType="ContentPresenter">
                                                <Setter Property="Margin" Value="0, 0, 5, 0" />
                                            </Style>
                                        </ItemsControl.ItemContainerStyle>
                                    </ItemsControl>
                                    <TextBlock Text="{Binding Title}" Style="{StaticResource TitleItemTextBlockStyle}"
                                               Grid.Row="1" TextWrapping="Wrap" TextTrimming="WordEllipsis" />
                                    <TextBlock Text="{Binding Summary}" Grid.Row="2" Style="{StaticResource SummaryItemTextBlockStyle}"
                                                   TextWrapping="Wrap" TextTrimming="WordEllipsis" />
                                </Grid>
                            </DataTemplate>
                        </GridView.ItemTemplate>
                        <GridView.ItemContainerStyle>
                            <Style TargetType="GridViewItem" BasedOn="{StaticResource CustomGridViewItemStyle}">
                                <Setter Property="Padding" Value="5" />
                                <Setter Property="VerticalContentAlignment" Value="Top" />
                            </Style>
                        </GridView.ItemContainerStyle>
                        <GridView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <ItemsWrapGrid ItemHeight="180" ItemWidth="300" />
                            </ItemsPanelTemplate>
                        </GridView.ItemsPanel>
                    </GridView>
                </DataTemplate>
            </HubSection.ContentTemplate>
        </HubSection>
    </Hub>
</internals:PageBase>
